package com.jiepu.exercise.advanceed.chapter1.test1;

/**
 * @Description:
 * @author: xinjie.txt
 * @date: 2020/7/15  9:51
 */
public class InnerStrMaxMin {
	public static  class staticinner{
		public static void getMaxMin(int[] array){
			int max=array[0];
			int min=array[0];
			for(int i = 1;i<array.length;i++) {
				max = array[i]>max?array[i]:max;
				min = array[i]<min?array[i]:min;
			}
			System.out.println("静态内部类，最大值为"+max+",最小值为："+min);
		}
	}

	public class memberinner{
		public void getMaxMin(int[] array) {
			int max = array[0];
			int min = array[0];
			for (int i = 1; i < array.length; i++) {
				max = max > array[i] ? max : array[i];
				min = min > array[i] ? array[i] : min;
			}
			System.out.println("成员内部类，最大值为"+max+",最小值为："+min);
		}
	}

	public static void main(String[] args) {
		int[] array= {1,5,9,3,4,6,4,7,9};

		class localinner{
			public void getnumber(int[] array) {
				int max=array[0];
				int min=array[0];
				for(int i = 1;i<array.length;i++) {
					max = array[i]>max?array[i]:max;
					min = array[i]<min?array[i]:min;
				}
				System.out.println("局部内部类，最大值为"+max+",最小值为："+min);
			}
		}
		//new staticinner().getMaxMin(array);
		new InnerStrMaxMin().new memberinner().getMaxMin(array);
		new localinner().getnumber(array);
		MaxMin mm = new MaxMin() {
			@Override
			public  void getNum(int[] array) {
				int max=array[0];
				int min=array[0];
				for(int i = 1;i<array.length;i++) {
					max = array[i]>max?array[i]:max;
					min = array[i]<min?array[i]:min;
				}
				System.out.println("匿名内部类，最大值为"+max+",最小值为："+min);
			}
		};
		mm.getNum(array);
	}
}
